<?php
/**
 * indexAction 
 * 
 * 必须实现方法action().并且文件名要与类名保持一致.
 *
 */
class SearchAction{
	
	public function action($_get){  //$_get是URL参数的数组和$_GET一样.如果不需要可以省略
		require_once "Action/common.php";

		//获取分页信息

		$page_num = 1;
		if($_get['page']){
			if($_get['page']>100){
				$page_num = 93;
			}
			else{
				$page_num = $_get['page'];
			}
		}

		$cid = CID;													//默认CID
		if($_get['cid']){
			$cid = $_get['cid'];
			$cid = getNoiseCid($cid);
		}

		$keyword = '';
		if($_get['keyword']){
			$keyword = urlencode($_get['keyword']);
		}else{
			echo "您查询的关键字不能为空";
			exit();
		}


		//查询淘宝客推广商品(taobao.taobaoke.items.get)

		$Taoapi->method = 'taobao.taobaoke.items.get';

		$Taoapi->fields = 'num_iid,iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,seller_credit_score,item_location,shop_click_url';

		$Taoapi->nick = USERNICK;

		$Taoapi->keyword = mb_convert_encoding(urldecode($keyword),"UTF-8", "gb2312");

		$Taoapi->cid = $cid;
		$Taoapi->page_no = $page_num;
		$Taoapi->page_size = PAGE_SIZE;

		//商家开始信用
		$Taoapi->start_credit = STARTCREDIT;
		//商家结束信用
		$Taoapi->end_credit = ENDCREDIT;
		//推广商品排序
		$Taoapi->sort = SORTBY;

		//需要更多的字段可以登陆 taoapi.com 进行配置生成
		$TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();
		
		$show_array=array();
		$show_array= $TaobaokeData['taobaoke_items']['taobaoke_item'];
		

		$page_size		= PAGE_SIZE;
		$pageCurrent	= $page_num;
		$sub_pages		= PAGE_ACTIVE;
		$nums			= ($TaobaokeData['total_results']>2000)?2000:$TaobaokeData['total_results'];	

		if($keyword==""){											//是否存在关键字
			$pageurl = SITEPATH."index.php/List/cid/".addNoise($d,$cid)."/page/";
		}
		else{
			$pageurl = SITEPATH."index.php/List/cid/".addNoise($d,$cid)."/keyword/". 
				mb_convert_encoding(urldecode($keyword),"UTF-8","gb2312")."/page/";
		}




		$subPages = new SubPages($page_size,$nums,$pageCurrent,$sub_pages,SITEPATH.$pageurl,2);
		$pages    = $subPages->subPageCss2();

		//分配变量

		$tpl->assign("mm_index_key",KEYW.$list['listtitle']);		//关键字
		$tpl->assign("nobaiduContent",$article);
		$tpl->assign("mm_index_des",DES.$list['lists']);			//描述

		$tpl->assign("nobaidu",$nobaidu);							//不是百度?

		$tpl->assign("mm_beian",ICPBEIAN);
		$tpl->assign("mm_pages",$pages);
		$tpl->assign("item",$show_array);
		$tpl->assign("mm_webname",SITETITLE);
		$tpl->display("mm_index.html","index");	

	}
}
?>